// 获取未复习错题的题目索引
import { NextRequest } from 'next/server';
import { MistakeDB } from '@/lib/mysql';
import { getCurrentUser, ApiResponse } from '@/lib/auth';

// 获取用户所有未复习的错题索引（返回 {topic_id, question_index} 格式）
export async function GET(request: NextRequest) {
  try {
    // 验证用户登录
    const currentUser = getCurrentUser();
    if (!currentUser) {
      return ApiResponse.unauthorized('请先登录');
    }

    // 获取未复习的错题索引（所有知识点）
    const unreviewedMistakes = await MistakeDB.getUnreviewedIndices(
      currentUser.userId
    );

    return ApiResponse.success({ unreviewedMistakes });
  } catch (error) {
    console.error('获取未复习错题索引错误:', error);
    return ApiResponse.serverError('获取未复习错题索引失败');
  }
}

